Auto start dev server in VSCode

Posted on 2023-09-12 by

henrikvilhelmberglund

I opened localhost:5173 and got a 404 and was very sad. I had forgotten to start the dev server (again).

Why not start the server automatically whenever you open a project in VSCode? Here's how to do that!

  • 1. In VSCode, open the command palette and run Tasks: Open User Tasks
  • 2. In there paste the following to replace the contents (assuming you don't have anything else there you would like to keep:)
{
	"version": "2.0.0",
	"tasks": [
		{
			"label": "Start Dev Server",
			"type": "shell",
			"command": "ni && d",
			"runOptions": { "runOn": "folderOpen" },
			"group": {
				"kind": "none",
				"isDefault": true
			},
			"presentation": {
				"reveal": "always",
				"panel": "new"
			}
		}
	]
}
  • 3. Replace the command with the actual command you would like to use, for example "npm install && npm run dev" to automatically install and after running run the dev server.
  • 4. After the changes every time you open a new folder in VSCode you will start a dev server automatically.
  • 5. Success! I hope it helped!